<template>
  <div class="card">
    <div class="card-header">
      <h3 class="card-title">🛒 订单复购分析</h3>
      <a href="#" class="link">查看全部</a>
    </div>

    <div class="grid">
      <!-- 复购客户 -->
      <div class="stat-box">
        <div class="icon-wrapper">
          <img :src="fgkhImg" alt="" />
        </div>
        <div class="stat-content">
          <div class="stat-value">{{ formatNumber(234) }}</div>
          <div class="stat-label">复购客户 (18.9%)</div>
        </div>
      </div>

      <div class="stat-box">
        <div class="icon-wrapper">
          <img :src="pjfgcsImg" alt="" />
        </div>
        <div class="stat-content">
          <div class="stat-value">¥{{ formatNumber(4545) }}</div>
          <div class="stat-label">平均单次收入</div>
        </div>
      </div>

      <!-- 复购总金额 -->
      <div class="stat-box">
        <div class="icon-wrapper">
          <img :src="fgjeImg" alt="" />
        </div>
        <div class="stat-content">
          <div class="stat-value">{{ formatNumber(89123) }}</div>
          <div class="stat-label">复购总金额 (36.4%)</div>
        </div>
      </div>

      <!-- 平均复购客户 -->
      <div class="stat-box">
        <div class="icon-wrapper">
          <img :src="fgpjjeImg" alt="" />
        </div>
        <div class="stat-content">
          <div class="stat-value">¥{{ formatNumber(3247) }}</div>
          <div class="stat-label">平均复购客户</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
// fgkh 复购客户
import fgkhImg from "@/assets/images/dashboard/admin/fgkh.png";
// pjfgcs 平均复购次数
import pjfgcsImg from "@/assets/images/dashboard/admin/pjfgcs.png";
// fgje 复购金额
import fgjeImg from "@/assets/images/dashboard/admin/fgje.png";
// fgpjje 复购平均金额
import fgpjjeImg from "@/assets/images/dashboard/admin/fgpjje.png";
// 格式化数字：千分位
const formatNumber = (num: number): string => {
  return num.toLocaleString();
};
</script>

<style scoped>
.card {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
  padding: 16px;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.card-title {
  font-size: 16px;
  font-weight: 600;
  color: #2c3e50;
  display: flex;
  align-items: center;
  gap: 6px;
}

.link {
  font-size: 13px;
  color: #409eff;
  text-decoration: none;
  font-weight: 500;
}

.link:hover {
  text-decoration: underline;
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  flex: 1; /* 关键：占满剩余高度 */
  min-height: 0;
}

.stat-box {
  display: flex;
  align-items: center;
  background: #f9fafb;
  border-radius: 10px;
  padding: 14px;
  transition: all 0.2s ease;
  height: 100%; /* 铺满高度 */
  box-sizing: border-box;
}

.stat-box:hover {
  background: #f1f5f9;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.06);
}

.icon-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  margin-right: 12px;
  flex-shrink: 0;
}

.icon {
  font-size: 18px;
}

/* 背景与图标配色 */
.purple-bg {
  background: #f3e5f5;
  color: #6a1b9a;
}

.blue-bg {
  background: #e3f2fd;
  color: #1e88e5;
}

.green-bg {
  background: #e8f5e8;
  color: #43a047;
}

.orange-bg {
  background: #fff3e0;
  color: #ef6c00;
}

.stat-content {
  flex: 1;
  text-align: center;
}

.stat-value {
  font-size: 18px;
  font-weight: 600;
  color: #1e293b;
  text-align: left;
}

.stat-label {
  font-size: 13px;
  text-align: left;
  color: #666;
  margin-top: 4px;
}
</style>
